# -*- coding: utf-8 -*-

import mod.server.extraServerApi as serverApi
from enchantBase import EnchantBase


class IceFrozen(EnchantBase):
    def __init__(self, system, playerId, enchantData, levels):
        EnchantBase.__init__(self, system, playerId, enchantData, levels)

    def onEnter(self):
        self.mSystem.ListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(),
                                    'DamageEvent', self, self.frozen)

    def onExit(self):
        self.mSystem.UnListenForEvent(serverApi.GetEngineNamespace(), serverApi.GetEngineSystemName(),
                                      'DamageEvent', self, self.frozen)

    def isArmorEnchant(self):
        return False

    def frozen(self, args):
        src_id = args['srcId']
        entity_id = args['entityId']
        level = self.levels
        if src_id != self.playerId:
            return
        if entity_id == src_id:
            return
        comp = serverApi.GetEngineCompFactory().CreateEffect(entity_id)
        res = comp.AddEffectToEntity("slowness", int(level[0]), int(level[0]), True)
        pass
